﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MINERP.DAL.NewPhotoRindGrid;
using MINERP.MODEL.NewPhotoRindGrid;
using MINERP.COM;

namespace MINERP.BLL.NewPhotoRindGrid
{
    /// <summary>
    /// 处理与分片中要用到定单信息相关的BLL
    /// 0:成功 1-输入的参数有误，2：从数据库取数据时出错，3：没有得到相关的定单信息，要么被删除了
    /// </summary>
    public class OrderInfoBLL_Grid
    {

        //根据产品ID得到相应的产品信息
        public int GetOrderInfo_Grid(int orderProductId, out OrderInfo_Grid oInfo_Grid)
        {
            int result = 0;//操作成功
            oInfo_Grid = null;
            OrderInfoDAL_Grid _orderInfoDAL = new OrderInfoDAL_Grid();
            PhotoBLL_Grid _photoBll = new PhotoBLL_Grid();
            if (orderProductId > 0)
            {
                result = _orderInfoDAL.GetOrderInfo_Grid(orderProductId, out oInfo_Grid);
                oInfo_Grid.OrderProductCode = "2" + orderProductId.ToString().PadLeft(9, '0');
                
                oInfo_Grid.PhotoS = _photoBll.GetPhotosByOrderProductId(orderProductId,out result);
            }
            else
            {
                result = 1;//办理入的orderProductId不正确
            }

            return result;
        }

     
        /// <summary>
        /// 得到产品的当前的节点ID以及其状态
        /// </summary>
        /// <param name="orderProductId"></param>
        /// <param name="curTechId"></param>
        /// <param name="status"></param>
        /// <returns></returns>

        public int GetTechIdByOrderProductId(int orderProductId, out int curTechId, out OrderFlowListStatus status)
        {
            int result = 1;
            curTechId = 0;
            status = 0;

            if (orderProductId > 0)
            {
                OrderInfoDAL_Grid _orderInfoDAL = new OrderInfoDAL_Grid();

                result = _orderInfoDAL.GetLastTechIdByOrderProductId(orderProductId, out curTechId, out status);
            }
            else
            {
                result = -1;
            }
            return result;
        }

        /// <summary>
        /// 检查产品的所有照片是否都分片完成
        /// </summary>
        /// <param name="orderProductId"></param>
        /// <param name="isCompleted"></param>
        /// <returns></returns>
        public int CheckOrderPhotoAssignCompleted(int orderProductId, out bool isCompleted)
        {
            int result = 1;
            isCompleted = false;

            if (orderProductId > 0)
            {
                OrderInfoDAL_Grid _dal = new OrderInfoDAL_Grid();
                result = _dal.CheckOrdersPhotoIsAssignCompleted(orderProductId, (int)PhotoStatus.FenPian);
                if (result == 1)//全部完成
                {
                    isCompleted = true;
                }
                else if (result == 0)
                {
                    result = 1;
                    isCompleted = false;
                }
            }
            else
            {
                result = -1;
            }

            return result;
        }

        //完成产品的分片结点
        public int OverOrderFlow(int orderProudctId, bool isReBackOrder, int Uid, out string nextTechName)
        {
            int result = 1;
            nextTechName = "";

            if (orderProudctId > 0 && Uid > 0)
            {
                OrderInfoDAL_Grid _orderInfoDAL = new OrderInfoDAL_Grid();
                result = _orderInfoDAL.OrverOrderProductFlowTech(orderProudctId, isReBackOrder, Uid, out nextTechName);
            }
            else
            {
                result = -1;
            }
            return result;
        }
    }
}
